Formal Logic: The study of reasoning, specifically whether something is true or false.
Statement / Proposition: A sentence that is either true or false.
Examples of Valid Statements (crossed-out aren’t valid):
- “All mathematician wear sandals”
- “5 is greater than -2”
“Where do you live?”“Are you a cool person?”- “Anyone who wears sandals is an algebraist”
Logical methods are used to prove that programs do what they are designed to do.
Example of a Logically-Sound Proof/Derivation:
- All mathematicians wear sandals
- Anyone wears sandals is an algebraist
- Therefore, all mathematicians are algebraists
Example of Logical Connective and Disjunction:
A B A \land B A \lor B T T T T T F F T F T F T F F F F
Example of Logical Implication and Equivalence Connective:
A B A \rightarrow B B \rightarrow A (A \rightarrow B) \land (B \rightarrow A) T T T T T T F F T F F T T F F F F T T T
Truth Table: Table that displays the truth values of a statement which correspond to the different combinations of truth values for the variables.
General Structure of a Truth Table:
How-To Make a Truth Table:
Note: Truth tables get graded in the test/homework by whether the target truth values are correct
- Points won’t get taken off for a lack of intermediate values.
- However, if the target truth value is wrong, the intermediate values will be used to give partial credit
A \rightarrow B and A` \lor B are tautologically equivalent
Proof: Truth table for A \rightarrow B \equiv A` \lor B
A B A \to B \lnot A \lor B T T T T T F F F F T T T F F T T
Example: These two statements are equivalent
- “If you do your homework, then you will fail”
- A \rightarrow B
- “Either you do your homework or you will fail”
- \lnot A \lor B
Well-Formed Formula: A combination of letters, connectives, and parenthesis in a meaningful expression.
De Morgan’s Law: A pair of transformation rules to negate statements
Examples:
- ( A \lor B ) \leftrightarrow A' \land B'
- ( A \land B )' \leftrightarrow A' \lor B'
How-To Apply De Morgan’s:
Hint: If you need to negate a statement with a \to in it, remember that A \rightarrow B \equiv A` \lor B
Note: To simplify statements, we use letters near the end of the alphabet, by convention usually P and Q.
- e.g., ( A \land B )' \rightarrow A' \lor B' getting rewritten as P \rightarrow Q
Tautology: A well-formed formula that is always true.
Contradiction: A well-formed formula that is always false.
Note: Mathematicians call tautologies and contradictions “intrinsically true” and “intrinsically false”, respectively.
Logical Equivalence: Two statements are logically equivalent if, and only if, they have identical truth for every possible combination of statement variables.
We can write logical equivalence with \Leftrightarrow and \equiv, like so:
Communicative | A \lor B \equiv B \lor A | A \land B \equiv B \land A |
---|---|---|
Distributive | (A \lor B) \lor C \equiv A \lor (B \lor C) | (A \land B) \land C \equiv A \land (B \land C) |
Identity | A \lor 0 \equiv A | A \land 1 \equiv A |
Component | A \lor A' \equiv 1 | A \land A' \equiv 0 |
Further Explanation:
True || False === True
, True && True === True
Conditional statements in programming use logical connectives with statements.
if (outflow > inflow) and not (pressure 1000)
do something;
else
do something else
Problem: Negate the following statements:
Solution:
Answers:
Problem: Translate the following using statement letters A, T, and E.
Solution:
Notes:
- “only if” is unidirectional (\rightarrow)
- “if and only if” is bidirectional (\leftrightarrow)